

#ifndef   _UCDBTRANS_H__
#define   _UCDBTRANS_H__

#include "zdbapserv.h"

#pragma pack (push, 8)

class UcTransaction;
class UcTransactionReactor;

class UcDbTransactionManager: public UcRxObject
{ 
public:
    UCRX_DECLARE_MEMBERS(UcDbTransactionManager);

    virtual UcTransaction*      startTransaction() = 0;
    virtual Ucad::ErrorStatus   endTransaction  () = 0;
    virtual Ucad::ErrorStatus   abortTransaction() = 0;

    virtual int                 numActiveTransactions() = 0;
    virtual UcTransaction*      topTransaction() = 0;
    virtual Ucad::ErrorStatus   addNewlyCreatedDBRObject(UcDbObject* obj,
                                     bool add = true) = 0;

    virtual Ucad::ErrorStatus   getAllObjects(UcDbVoidPtrArray& objs) = 0;

    virtual void                addReactor(UcTransactionReactor* reactor) = 0;
    virtual void                removeReactor(UcTransactionReactor* reactor) =0;

    virtual Ucad::ErrorStatus   getObject(UcDbObject*& obj, UcDbObjectId id,
                                          UcDb::OpenMode mode, 
                                          bool openErasedObj = false) = 0; 

    virtual Ucad::ErrorStatus   markObjectPageable(UcDbObject* pObject) = 0;
    virtual Ucad::ErrorStatus   queueForGraphicsFlush() = 0;

};

class UcTransaction: public UcRxObject
{ 
public:
    UCRX_DECLARE_MEMBERS(UcTransaction);
    virtual 
    Ucad::ErrorStatus getObject(UcDbObject*& obj, 
                                UcDbObjectId   objectId, UcDb::OpenMode mode,
                                bool openErasedObject = false) = 0;

    virtual 
    Ucad::ErrorStatus markObjectPageable(UcDbObject* pObject) = 0;

    virtual Ucad::ErrorStatus   getAllObjects(UcDbVoidPtrArray& objs) = 0;
};

class UcTransactionReactor: public UcRxObject

{
public:
    UCRX_DECLARE_MEMBERS(UcTransactionReactor);

    virtual void transactionAboutToStart (int& numTransactions,
        UcDbTransactionManager* transactionManagerPtr);
    virtual void transactionStarted      (int& numTransactions,
        UcDbTransactionManager* transactionManagerPtr);
    virtual void transactionAboutToEnd   (int& numTransactions,
        UcDbTransactionManager* transactionManagerPtr);
    virtual void transactionEnded        (int& numTransactions,
        UcDbTransactionManager* transactionManagerPtr);
    virtual void transactionAboutToAbort (int& numTransactions,
        UcDbTransactionManager* transactionManagerPtr);
    virtual void transactionAborted      (int& numTransactions,
        UcDbTransactionManager* transactionManagerPtr);
    virtual void endCalledOnOutermostTransaction (int& numTransactions,
        UcDbTransactionManager* transactionManagerPtr);
    virtual void objectIdSwapped (const UcDbObject* pTransResObj,
        const UcDbObject* pOtherObj,
        UcDbTransactionManager* transactionManagerPtr);
};

inline UcDbTransactionManager* ucdbTransactionManagerPtr()
{
    return ucdbHostApplicationServices()->workingTransactionManager();
}

#define ucdbTransactionManager  ucdbTransactionManagerPtr()

#pragma pack (pop)

#endif   _UCDBTRANS_H__
